﻿package com.wly.ui
{
	import com.wly.ItemEditerMain;
	import com.wly.data.TypeVO;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class TypeItem extends Sprite
	{
		private var _tfId:TextField;
		private var _tfDesc:TextField;
		private var _selectFlag:MovieClip;
		private var _typeVo:TypeVO;
		
		public var index:int = -1;
		public var typeGrid:TypeGrid;
		
		public function TypeItem()
		{
			super();
			initChilds();
		}
		
		private function initChilds():void
		{
			_tfId   = getChildByName("tfType") as TextField;
			_tfDesc = getChildByName("tfDesc") as TextField;
			_selectFlag = getChildByName("mcSelect") as MovieClip;
			_selectFlag.gotoAndStop(1);
			
			addEventListener(MouseEvent.CLICK, onClick);
		}
		
		private function onClick(e:MouseEvent):void
		{
			selected = !selected;
			if(typeGrid)
			{
				typeGrid.onTypeSelectChg(index);
			}
		}
		
		public function getTypeInfo():TypeVO
		{
			return _typeVo;
		}
		
		public function setTypeInfo(typeVo:TypeVO):void
		{
			_typeVo = typeVo;
			if(!typeVo)
			{
				return;
			}

			_tfId.text   = typeVo.id.toString();
			_tfDesc.text = typeVo.desc;
		}
		
		public function set selected(val:Boolean):void
		{
			if(val)
			{
				_selectFlag.gotoAndStop(2);
			}
			else
			{
				_selectFlag.gotoAndStop(1);
			}
		}
		
		public function get selected():Boolean
		{
			return _selectFlag.currentFrame == 2;
		}
	}
}